***DRAW FIGURE 4, Trade Cell***

version 15.1

clear
use "worms_replication.dta"
set more off

*keep only covered dioceses*
drop if covered == 0



egen year_trade = group(year trade_fixed)
collapse (mean) religious_bishop year trade_fixed, by(year_trade)

rename religious_bishop avg_religious_t

gen moving_avg_t = .
quietly forval i = 800/1289{
	sum avg_religious_t if year >= `i'-20 & year <= `i'+20 & trade_fixed == 1 
	replace moving_avg_t = r(mean) if year == `i' & trade_fixed == 1
	sum avg_religious_t if year >= `i'-20 & year <= `i'+20 & trade_fixed == 0
	replace moving_avg_t = r(mean) if year == `i' & trade_fixed == 0
	}

label var avg_religious_t "Share Religious Bishops"
label var moving_avg_t "Share Religious Bishops"
label var year "Year"

*For each year and each of trade and no trade plot both the share of religious bishops (avg_religious_t) and the moving average*
twoway (scatter avg_religious_t year if  trade == 0  & year >=800 & year <=1309, mcolor(black) lcolor(black))(line moving_avg_t year if trade == 0  & year >=800 & year <=1309, mcolor(black) lcolor(black))(scatter avg_religious_t year if trade ==1  & year >=800 & year <= 1309, mcolor(gs12) lcolor(gs12))(line moving_avg_t year if trade ==1  & year >800 & year <=1309, mcolor(gs12) lcolor(gs12) xline(1122, lpattern(dash) lcolor(black)) xline(1309, lpattern(dash) lcolor(black))), ///
   graphregion(color(white))  bgcolor(white) scheme(lean1)  xlab(800 900 1000 1100 1200 1300 )  ylab(, nogrid) legend(order(1 "poor diocese" 2 "poor diocese" 3 "wealthy diocese" 4 "wealthy diocese")) title("Trade")


 
  
